﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

/// <summary>
/// Summary description for common
/// </summary>
public class common
{
    public common()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static DataSet createDS(string sql)
    {
        SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlDataAdapter objDA = new SqlDataAdapter(sql, objConn);
        objDA.SelectCommand.CommandType = CommandType.Text;

        DataSet ds = new DataSet();
        objDA.Fill(ds);
        objConn.Close();
        return ds;
    }

    public static DataTable createDT(string sql)
    {
        SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlDataAdapter objDA = new SqlDataAdapter(sql, objConn);
        objDA.SelectCommand.CommandType = CommandType.Text;

        DataSet ds = new DataSet();
        try
        {
            objDA.Fill(ds);
        }
        catch (Exception ex)
        {
            HttpContext.Current.Response.Write(sql);
            HttpContext.Current.Response.Flush();
            throw ex;
        }
        finally
        {
            objConn.Close();
        }


        return ds.Tables[0];
    }

    public static void DisableControls(Control parent)
    {
        foreach (Control c in parent.Controls)
        {
            
            if (c is DropDownList)
            {
                ((DropDownList)(c)).Enabled = false;
            }

            else if (c is TextBox )
            {
                ((TextBox)(c)).Enabled = false;
            }
            else
            {
                DisableControls(c);    
            }

            
        }
    }
  

}
